package com.woniu.humanresource.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.humanresource.entity.Accets;
import com.woniu.humanresource.entity.AssetsCategory;
import com.woniu.humanresource.entity.ResponseText;
import com.woniu.humanresource.service.AssetsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class AssetsCategoryController {
    @Autowired
    AssetsCategoryService assetsCategoryService;

    //查询所有
    @PostMapping("/assetscategory")
    public ResponseText<List<AssetsCategory>> getAllAssetsCategory(){

        List<AssetsCategory> assetsCategories = assetsCategoryService.getAllAssetsCategory();//调service方法去查询
        ResponseText<List<AssetsCategory>> responseText=new ResponseText<>(assetsCategories, 200, "OK");//返回一个带有树状的分类
        return responseText;
    }

    //添加根节点
    @PostMapping("/addRootNodeAssetsCategory/{newAssetsCategoryName}")
    public ResponseText<List<AssetsCategory>> addRootNodeAssetsCategory(@PathVariable("newAssetsCategoryName") String newAssetsCategoryName){
        System.out.println("■■■■■■添加■■■■■■"+newAssetsCategoryName);

        assetsCategoryService.addRootNodeAssetsCategory(newAssetsCategoryName);//调service方法去插入
        ResponseText<List<AssetsCategory>> responseText=new ResponseText<>(null, 200, "OK");//返回一个空信息的状态响应
        return responseText;
    }

    //添加子节点分类
    @PostMapping("/addAssetsCategory/{newAssetsCategoryName}")
    public ResponseText<List<AssetsCategory>> addAssetsCategory(@PathVariable("newAssetsCategoryName") String newAssetsCategoryName,
                                                                @RequestBody AssetsCategory assetsCategory){
        System.out.println("■■■■■■添加■■■■■■"+newAssetsCategoryName+"/"+assetsCategory);

        assetsCategoryService.addAssetsCategory(newAssetsCategoryName,assetsCategory);//调service方法去插入
        ResponseText<List<AssetsCategory>> responseText=new ResponseText<>(null, 200, "OK");//返回一个空信息的状态响应
        return responseText;
    }

    //删除
    @DeleteMapping("/removeAssetsCategory")
    public ResponseText<Page<Accets>> removeAssetsById(@RequestBody List<AssetsCategory> assetsCategories){
        System.out.println("■■■■■■删除■■■■■■"+assetsCategories);

        assetsCategoryService.removeAssetsCategory(assetsCategories);
        ResponseText<Page<Accets>> responseText=new ResponseText<>(null, 200, "OK");
        return responseText;
    }

    //编辑
    @PutMapping("/editAssetsCategory/{newAssetsCategoryName}")
    public ResponseText<List<AssetsCategory>> editAssetsCategory(@PathVariable("newAssetsCategoryName") String newAssetsCategoryName,
                                                                 @RequestBody AssetsCategory assetsCategory){
        System.out.println("■■■■■■编辑■■■■■■"+newAssetsCategoryName+"/"+assetsCategory);

        assetsCategoryService.editAssetsCategory(newAssetsCategoryName,assetsCategory);//调service方法去插入
        ResponseText<List<AssetsCategory>> responseText=new ResponseText<>(null, 200, "OK");//返回一个空信息的状态响应
        return responseText;
    }
}
